#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <unordered_map>
using namespace std;
using LL = long long;
int n;
const int N = 100010;
int lsum[N], rsum[N];
string s;
int main()
{
    cin >> s;
    n = s.size();
    unordered_map<char, int> hsh;
    hsh[s[n - 1]] = n - 1;
    for(int i = n - 2; i >= 0; --i)
    {
        const char c = s[i];
        if(hsh.count(c) == 0)
            rsum[i] = n - i - 1;
        else
            rsum[i] = hsh[c] - i - 1;
        hsh[c] = i;
    }
    
    hsh.clear();
    hsh[s[0]] = 0;
    for(int i = 1; i < n; ++i)
    {
        const char c = s[i];
        if(hsh.count(c) == 0)
            lsum[i] += i;
        else
            lsum[i] += i - 1 - hsh[c];
        hsh[c] = i;
    }
    LL ans = 0;
    for(int i = 0; i < n; ++i)
    {
        ans += 1;
        if(rsum[i] == 0)
            ans += lsum[i];
        else if(lsum[i] == 0)
            ans += rsum[i];
        else
            ans += (LL)rsum[i] * lsum[i] + lsum[i] + rsum[i];
    }
    cout << ans << endl;
    return 0;
}